﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pandora
{

    class Pandora
    {
        //trying to port pandora.py
        private const string _PROTOCOL_VERSION = "33";
        private const string _RPC_URL = "www.pandora.com/radio/xmlrpc/v" + _PROTOCOL_VERSION + "?";
        private const string _USER_AGENT = "Mozilla/5.0 (X11; U; Linux i586; de; rv:5.0) Gecko/20100101 Firefox/5.0 (compatible; Pithos/0.3)";
        private const string _AUDIO_FORMAT = "aacplus";
        private const string _RATE_BAN = "ban";
        private const string _RATE_LOVE = "love";
        private const string _RATE_NONE = null;  //is it a string
        private const int _HTTP_TIMEOUT = 30;
        private const int _PLAYLIST_VALIDITY_TIME = 60*60*3;
        private int _rid, _listenerID, _authToken;
        private bool _proxy = false;

        public Pandora() {}
        public Pandora(bool proxy)
        {
            this._proxy = proxy;
        }

        private string XmlrpcCall(string method, string[] args, bool url_args = true, bool secure = false, bool includeTime = true)
        {
            if (url_args)
            {
                url_args = args; //what type is args
            }

            if (includeTime)
            {
                //args.insert(0, int(time.time()+self.time_offset)) //what is args
            }

            if (this._authToken != null)//verify
            {
                //args.insert(1, self.authToken)
            }

            
            return "not sure it returns a string"; //prototype
        }

    }

    class Station
    {
        Pandora pandora;
        private string id;
        private string idToken;
        private bool isCreator; //bool
        private string isQuciMix; //bool
        private string name; //bool 
        private bool useQuickMix = false;

        public Station(Pandora pandora, Dictionary<string, string> pandoraDictionary)
        {
            this.pandora = pandora;
            this.id = pandoraDictionary["stationID"];
            this.idToken = pandoraDictionary["stationIDToken"];
            this.isCreator = pandoraDictionary["isCreator"];
            this.isQuciMix = pandoraDictionary["isQuickMix"];
            this.name = pandoraDictionary["stationName"];
        }

        private void TransformIfShared()
        {
            if (!this.isCreator)
            {
                //logging shit
                //do pandora xmlrpc_call("station.transformedShared", [this.id]")
                this.isCreator = true;
            }
        }

        private string Get_Playlist()
        {
            //logging shit
            //playlist = self.pandora.xmlrpc_call('playlist.getFragment', [self.id, '0', '', '', self.pandora.audio_format, '0', '0'])
            //return [Song(self.pandora, i) for i in playlist] type casting Pandora instance into Song object for every pandora object in playlist 
            return "Hello";
        }

        //python @property
        private string Info_Url()
        {
            return "http://www.pandora.com/stations/'" + this.idToken;
        }

        private void Rename(string newName)
        {
            if (newName != this.name)
            {
                //logging
                //this.pandora   self.pandora.xmlrpc_call('station.setStationName', [self.id, new_name])
                this.name = newName;
            }
        }

        private void Delete()
        {
            //logging
            //this.pandora self.pandora.xmlrpc_call('station.removeStation', [self.id])
        }

    }

    class Song
    {
        Pandora pandora;
        private string album;
        private string artist;
        private int artistMusicID;
        private string audioURL;
        private string fileGain; //is it a string 
        private string identity;
        private int musicID;
        private string trackToken; //?string? 
        private string rating;   //ban love 
        private int stationID; //?int?  ///better to put all these in a class as properties   
        private string title; //say no cuz need to iterate over them Dictionary<string, dynamic> d or Dictionary<string, object> d
        private string userSeed; //?string 
        private string songDetailURL;
        private string albumDetailURL;
        private string artRadio; //?string

        private bool tired = false;
        private string message = "";
        private int start_time; //int?
        private bool finished = false;
        private DateTime playListTime; //self.playlist_time = time.time()


        public Song(Pandora pandora, Dictionary<string, dynamic> d)
        {
            this.album = d["albumTitle"];
            this.artist = d["artistSummary"];
            this.artistMusicID = d["artistMusicId"];
            this.audioURL = d["audioURL"];//[:-48] + pandora_decrypt(d['audioURL'][-48:])
            this.fileGain = d["fileGain"];
            this.identity = d["identity"];
            this.musicID = d["musicID"];
            this.trackToken = d["trackToken"];
            this.rating = d["rating"];
            this.stationID = d["stationID"];
            this.title = d["title"];
            this.userSeed = d["userSeed"];
            this.songDetailURL = d["SongDetailURL"];
            this.albumDetailURL = d["albumDetailURL"];
            this.artRadio = d["artRadio"];
            this.playListTime = DateTime.Now;
            //private int start_time; //int?
        }

        private int Station()
        {
            return pandora; //return self.pandora.get_station_by_id(self.stationId)        
        }

        private int FeedBackID()
        {
            return pandora; //return self.pandora.get_feedback_id(self.stationId, self.musicId)
        }

        private void Rate(string rating)
        {
            if (this.rating != rating)
            {
                //self.station.transformIfShared() python property read up on @property
                if (rating == null)
                {
                    throw new NotImplementedException();
                    //self.pandora.delete_feedback(self.feedbackId)
                }

                else
                {
                    //throw new NotImplementedException();//self.pandora.add_feedback(self.stationId, self.trackToken, rating);
                }
                this.rating = rating;
            }
        }

        private void SetTired()
        {
            if (!(this.tired))
            {
                //self.pandora.xmlrpc_call('listener.addTiredSong', [self.identity])(IMPLEMENT)
                this.tired = true;
            }
        }

        private void BookMark()
        {
            //self.pandora.xmlrpc_call('station.createBookmark', [self.stationId, self.musicId]) (IMPLEMENT)
        }

        private void BookMarkArtist()
        {
            //self.pandora.xmlrpc_call('station.createArtistBookmark', [self.artistMusicId]) (IMPLEMENT)
        }

        private string RatingString() //@property
        {
            return this.rating;
        }

        private bool IsStillValid()
        {
            int PLAYLIST_VALIDITY_TIME = 60*60*3;
            DateTime saveNow = DateTime.Now;
            return ((saveNow.Millisecond - playListTime.Millisecond) < PLAYLIST_VALIDITY_TIME); //diff in time since UNIX EPOCH
        }
    }

    class SearchResult
    {
        private string resultType;
        private string score;
        private int musicID;
        private string name;

        public SearchResult(string resultType, Dictionary<string, dynamic> d)
        {
            this.resultType = resultType;
            this.score = d["score"];
            this.musicID = d["musicID"];
            
            if (resultType == "song")
            {
                string title = d["songTitle"];
                string artist = d["artistSummary"];
            }
            else if (resultType == "artist")
                name = d["artistName"];


        }
    }
}
